import {enableProdMode, NgZone} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {NavigationStart, Router} from '@angular/router';
import {ɵAnimationEngine as AnimationEngine} from '@angular/animations/browser';
import {getSingleSpaExtraProviders, singleSpaAngular} from 'single-spa-angular';
import {NZ_CONFIG} from 'ng-zorro-antd/core/config';
import {AppModule} from './app/app.module';
import {environment} from './environments/environment';
import {singleSpaPropsSubject} from './single-spa/single-spa-props';
import {GnHttpInterceptorConfig, GnLoginUser, GnRouteGuard, GnSiteInfo} from "geminis-ng";

if (environment.production) {
  enableProdMode();
}

const lifecycles = singleSpaAngular({
  bootstrapFunction: (singleSpaProps: any) => {
    singleSpaPropsSubject.next(singleSpaProps);
    const providers = getSingleSpaExtraProviders();
    providers.push([
      {
        provide: GnSiteInfo,
        useValue: singleSpaProps['siteInfo']
      },
      {
        provide: GnLoginUser,
        useValue: singleSpaProps['loginUser']
      },
      {
        provide: GnRouteGuard,
        useValue: singleSpaProps['routeGuard']
      },
      {
        provide: GnHttpInterceptorConfig,
        useValue: singleSpaProps['httpInterceptorConfig']
      },
      {
        provide: NZ_CONFIG,
        useValue: singleSpaProps['zorroConfig'],
      }
    ]);
    return platformBrowserDynamic(providers).bootstrapModule(AppModule);
  },
  template: '<everydata-root></everydata-root>',
  Router,
  NavigationStart,
  NgZone,
  AnimationEngine,
});

export const bootstrap = lifecycles.bootstrap;
export const mount = lifecycles.mount;
export const unmount = lifecycles.unmount;
